package com.ybl.store.backend.controller.user;

import com.ybl.store.backend.dto.resp.user.customer.CustomerNameRespDTO;
import com.ybl.store.backend.dto.resp.user.customer.CustomerPageRespDTO;
import com.ybl.store.backend.dto.req.user.customer.CustomerSaveReqDTO;
import com.ybl.store.backend.dto.req.user.customer.CustomerUpdateReqDTO;
import com.ybl.store.backend.service.user.CustomerService;
import com.ybl.store.common.entity.ListRespDTO;
import com.ybl.store.common.convention.result.Result;
import com.ybl.store.common.convention.result.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 顾客控制层
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/backend/customer")
public class CustomerController {
    
    private final CustomerService customerService;

    /**
     * 新增顾客
     */
    @PostMapping
    public Result<Void> saveCustomer(@RequestBody CustomerSaveReqDTO requestParam) {
        customerService.saveCustomer(requestParam);
        return Results.success();
    }

    /**
     * 删除顾客
     */
    @DeleteMapping
    public Result<Void> deleteCustomerById(@RequestParam Long id) {
        customerService.deleteCustomerById(id);
        return Results.success();
    }

    /**
     * 修改顾客
     */
    @PutMapping
    public Result<Void> updateCustomer(@RequestBody CustomerUpdateReqDTO requestParam) {
        customerService.updateCustomer(requestParam);
        return Results.success();
    }

    /**
     * 禁用顾客
     */
    @PutMapping("/ban")
    public Result<Void> banCustomer(@RequestParam Long id, @RequestParam Integer banFlag) {
        customerService.banCustomer(id, banFlag);
        return Results.success();
    }

    /**
     * 分页查询顾客
     */
    @GetMapping("/page")
    public Result<ListRespDTO<CustomerPageRespDTO>> pageCustomer(
            @RequestParam("pn") Integer pn,
            @RequestParam("ps") Integer ps,
            @RequestParam(required = false) Long clerkId,
            @RequestParam(required = false) String name)
    {
        return Results.success(customerService.pageCustomer(pn, ps, clerkId, name));
    }

    /**
     * 查询顾客名列表
     */
    @GetMapping("/list/name")
    public Result<ListRespDTO<CustomerNameRespDTO>> listCustomerName(@RequestParam(required = false) Long clerkId) {
        return Results.success(customerService.listCustomerName(clerkId));
    }
}
